<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <!-- 
      单项数据流:

      当父组件的数据发生了改变，并传递给了子组件
      那么子组件的内容会自动的更新(是具有响应式的)

      子组件接受的props都是只读的
      只能从父组件去接收，但是不能进行修改
    -->
    <h1>单项数据流 - {{count}}</h1>
    <button @click="count++">count++</button>
    <hr>
    <child :count="count" :obj="obj"></child>
  </div>

  <script src="../Vue.js"></script>

  <script>
    const { createApp } = Vue;

    const Child = {
      props: {
        count: Number,
        obj: Object
      },
      data() {
        return {
          count2: this.count
        }
      },
      computed: {
        count3() {
          return this.count + 2
        }
      },
      template: `
        <div>这是子组件 - {{count3}}</div>
        <div>{{obj}}</div>
        <button @click="obj.a++">child count++</button>
      `
    }
    
    const app = createApp({
      data() {
        return {
          count: 10,
          obj: {a: 3, b: 4}
        }
      },
      methods: {},
      components: {
        Child
      }
    })

    app.mount("#app")
  </script>
</body>
</html>